//
//  WSJBundleVersionManger.m
//  WCN
//
//  Created by wsj2015 on 16/7/4.
//  Copyright © 2016年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WSJBundleVersionManger.h"
#import "WCNLoginVC.h"
#import "WCNNavigationController.h"
#import "WCNTabBarVC.h"

@implementation WSJBundleVersionManger
{
    UIWindow *_window;
}
+ (instancetype)manager{
    return [[self alloc] init];
}



- (WSJBundleVersionManger * (^)(UIWindow *))setWindow{

    defineWeakSelf;
    return ^id(UIWindow *window){
        _window = window;
        [weakSelf prepareForBoundleVersionKey:window];
        return weakSelf;
    };
 
}
- (void)prepareForBoundleVersionKey:(UIWindow *)window{
    NSString *lastVersion =[[NSUserDefaults standardUserDefaults] stringForKey:@"CFBundleVersion"];
    NSString *currentVersion =[NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
    
    if (self.isNeedNewFeaturePage ==YES) {
        
    }else{
        if ([currentVersion isEqualToString:lastVersion]) {
            
            [self goIntoApp];
        } else {
            [self goIntoApp];
//            self.window.rootViewController = [self getNewFeatureController];
            [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:@"CFBundleVersion"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
        
    
    }
    
   
    
    //使用appearance统一修改UI外观
    [UITableView appearance].separatorColor = kBorderColor;
    [_window makeKeyAndVisible];
    
    
}
- (void)goIntoApp{
    if (![[WCDefaultManager shareMg] account]) {
        WCNLoginVC *loginVC = [[WCNLoginVC alloc] init];
        WCNNavigationController *nav = [[WCNNavigationController alloc] initWithRootViewController:loginVC];
        
        
        _window.rootViewController = nav;
        
        
        [_window makeKeyAndVisible];
        
        
        
    } else {
        WCNTabBarVC *mainVC = [[WCNTabBarVC alloc] init];
        WCNNavigationController *nav = [[WCNNavigationController alloc] initWithRootViewController:mainVC];
        
        
        _window.rootViewController =nav;
        [_window makeKeyAndVisible];
    }


}
@end
